from django.shortcuts import render
from django.views import View
from django.shortcuts import redirect
from utils.tencent.cos import delete_bucket
from web import models


class SettingView(View):
    '''
    设置页面
    '''
    def get(self,request,project_id):

        return render(request,'web/settings.html')

class SettingProjectView(View):
    '''
    项目删除页面
    '''
    def get(self,request,project_id):
        return render(request,'web/setting_delete.html')
    def post(self,request,project_id):
        project_name=request.POST.get('project_name')
        if not project_name or project_name!=request.tracer.project.name:
            return render(request,'web/setting_delete.html',{'error':'项目名错误'})
        if request.tracer.user !=request.tracer.project.creator:
            return render(request,'web/setting_delete.html',{'error':'只有项目创建者才能删除项目'})
        delete_bucket(request.tracer.project.bucket,request.tracer.project.region)
        models.Project.objects.filter(id=request.tracer.project.id).delete()
        return redirect('web:project_list')